package jfrederick8;

import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;

/**
 * This class acts as a master object which has access to all other objects necessary for running the game
 * 
 * @author John Frederick
 * @version 1.0 - 11 February 2012
 */
public class Distributer implements MouseListener, MouseMotionListener{
	/** this is the field of play on which the StoryCharacters interact */
	private Field field;
	/** this is the panel on which the field is displayed */
	private MainPanel mainPanel;
	//TODO:javadoc
	private Graphics g;
	/** this is the object in charge of drawing all of the other objects */
	private DrawAll drawing;
	/** input test level */
	private File fieldTest;
	
	/**
	 * This constructs the objects necessary to run the game 
	 */
	public Distributer(){
		//Test Field
		fieldTest = new File("levelText" + File.separator + "fieldTest.txt");
		field = new Field(20,20,fieldTest);
		//field.setOverlay(6,4,4);

		mainPanel = new MainPanel(this);
		drawing = new DrawAll(this);
		mainPanel.addMouseMotionListener(this);
		mainPanel.addMouseListener(this);
		//end test
	}//end constructor Distributer
	
	/**
	 * Allows access to the graphics on which everything should be drawn
	 * 
	 * @return the display graphics
	 */
	public Graphics getGraphics(){
		return g;
	}//end getter getGraphics
	
	/**
	 * Allows access to the panel on which everything will be displayed
	 * 
	 * @return the main panel for the game's GUI
	 */
	public MainPanel getMainPanel(){
		return mainPanel;
	}//end getter getMainPanel
	
	/**
	 * Allows access to the field of play
	 * 
	 * @return the game's current field of play
	 */
	public Field getField(){
		return field;
	}//end getter getField
	
	/**
	 * Allows access to the drawing methods
	 * 
	 * @return the object which draws everything necessary to interact with the game
	 */
	public DrawAll getDrawing(){
		return drawing;
	}//end getter getDrawing
	
	/**
	 * regulates mouse movement events
	 */
	@Override
	public void mouseMoved(MouseEvent arg0) {
		//cursor settings
		if ((arg0.getX() < (field.getTiles()[0][0].getWidth() * field.getTiles().length))&&(arg0.getY() < (field.getTiles()[0][0].getHeight() * field.getTiles()[0].length))){
			drawing.setCursorX(arg0.getX()/field.getTiles()[0][0].getWidth());
			drawing.setCursorY(arg0.getY()/field.getTiles()[0][0].getHeight());
		}
		//basic description box movement
		if (drawing.getDescOnRight()){
			if ((arg0.getX()/field.getTiles()[0][0].getWidth()) >= (field.getTiles().length - 8)){
				if ((arg0.getY()/field.getTiles()[0][0].getHeight()) >= (field.getTiles()[0].length - 7)){
					drawing.setDescOnRight(false);
				}
			}
		} else {
			if ((arg0.getX()/field.getTiles()[0][0].getWidth()) <= (4 + (100/field.getTiles()[0][0].getWidth()))){
				if ((arg0.getY()/field.getTiles()[0][0].getHeight()) >= (field.getTiles()[0].length - 7)){
					drawing.setDescOnRight(true);
				}
			}
		}
		mainPanel.repaint();
	}//end method mouseMoved

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}//end method mouseClicked

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}//end method mouseEntered

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}//end method mouseExited

	public void mouseDragged(MouseEvent arg0) {}//unused
	public void mousePressed(MouseEvent arg0) {}//unused
	public void mouseReleased(MouseEvent arg0) {}//unused
}//end class Distributer
